<template>
	<view class="">
		<view class="title">
			<up-navbar title="扫码" bgColor="#F7F8FC" :titleStyle="{color:'black',fontWeight:600}" :placeholder="true"
				:autoBack="false">
				<template #left>
					<view class="u-nav-slot" @click="leftClick">
						<up-icon name="arrow-left" size="22"></up-icon>
					</view>
				</template>
			</up-navbar>
		</view>
	</view>
	<view class="">
		<view class="state_box flex" :style="{justifyContent: 'center',top:statusBarHeight + 'rpx'}" v-if="isShowState">
			<view class="m_r_8 m_t_4">
				<up-image :show-loading="true" src="/static/images/index/sm_success_icon.png" width="34rpx"
					height="34rpx"></up-image>
			</view>
			<view class="">
				<text class="f_26_3" style="color: #39AE37;">
					支付成功
				</text>
			</view>
		</view>
	</view>
	<view class="content" :style="{minHeight:contentHeight}">
		<view class="main">
			<view class="row1 goods_box m_t_36 m_b_68">
				<view class=" flex_both" style="align-items: flex-start;">
					<view class=" flex_both m_b_30">
						<view class="m_r_28">
							<up-image :show-loading="true" :src="storeDetail.shop_images.split(',')[0]" width="160rpx"
								height="146rpx" radius="5"></up-image>
						</view>
						<view class="">
							<view class="m_b_12">
								<text class="f_30_0_b">
									{{storeDetail.shop_name}}
								</text>
							</view>
							<view class="">
								<view class="flex">
									<view class="m_r_12 m_b_6">
										<up-image :show-loading="true" src="/static/images/index/clock_icon.png"
											width="28rpx" height="28rpx"></up-image>
									</view>
									<view class="">
										<text class="f_24_0" style="color: #737272;">
											{{storeDetail.begin_hour}} - {{storeDetail.end_hour}}
										</text>
									</view>
									<view class="f_26_0 m_l_12 m_r_12 m_t_6" style="color: #737272;">
										<text>
											|
										</text>
									</view>
									<view class="">
										<text class="f_24_0" style="color: #FE450C;" v-if="storeDetail.is_yingye">
											营业中
										</text>
										<text class="f_24_0" style="color: #737272;" v-else>
											已打烊
										</text>
									</view>
								</view>
							</view>
							<view class="flex" style="align-items: flex-start;">
								<view class="m_r_6 m_b_10 m_l_6" style="width: 28rpx; height: 28rpx;flex-shrink: 0;">
									<up-image :show-loading="true" src="/static/images/index/position_icon.png"
										width="18rpx" height="24rpx"></up-image>
								</view>
								<view class="">
									<text class="f_24_0" style="color: #737272;">
										{{storeDetail.address}}
									</text>

								</view>
							</view>
						</view>
					</view>

				</view>
			</view>
			<view class="row2 m_b_58">
				<view class=" m_b_38 flex_both" style="width: 710rpx;padding: 0 10rpx;">
					<view class="" style="width: 96rpx;">
						<text>

						</text>
					</view>
					<view class="">
						<text class="f_32_0_b">
							服务车型（{{role == 1?'集团用户':'普通用户'}}）
						</text>
					</view>

					<view class="flex" @click="switchRole" style="width: 96rpx;">
						<view class="" style="color: #737272;padding: 10rpx; padding-right: 0;"
							v-if="userInfo.is_jituan_user">
							<text class="f_24_f m_b_4" style="color: #737272;">
								切换
							</text>
						</view>

					</view>
				</view>
				<view class="">
					<view class="row2_list flex">
						<view
							:class="['row1_item','m_b_14',index%3!==0?'m_l_14':'',index == row2ActiveIdx?'row1_item_active':'']"
							v-for="(item,index) in row2List" :key="index" @click="onClickRow2Item(index)"
							:style="{backgroundImage:index == row2ActiveIdx?`url(${row1ActiveBg})`:'',background:index == row2ActiveIdx?'':'#ffffff'}">
							<view class="m_b_14 flex" style="height: 74rpx;">
								<up-image :show-loading="true" :src="item.type_image" width="178rpx" height="52rpx"
									mode="widthFix"></up-image>
							</view>
							<view class="">
								<text class="f_28_0_b">
									{{item.type_name}}
								</text>
							</view>
						</view>
						<view class="" v-if="row2List.length == 0">
							<text class="f_28_6_b">
								没有次数
							</text>
						</view>
					</view>
				</view>
			</view>
			<view class="row3 m_b_166">
				<view class="ro3_list">
					<view class="row3_item flex_both m_b_32">
						<view class="">
							<text class="f_26_0">
								本次洗车抵扣
							</text>
						</view>
						<view class="f_24_0" style="color: #FE450C;">
							X 1
						</view>
					</view>
					<view class="row3_item flex_both">
						<view class="">
							<text class="f_26_0">
								时间： {{curTime}}
							</text>
						</view>
					</view>
				</view>
			</view>
			<view class="submit_btn" @click="showConfirm()">
				<text class="f_30_f">
					完成
				</text>
			</view>
		</view>
	</view>
	<up-modal :show="confirmShow" title="提示" content='即将进行核销操作，是否继续？' :show-cancel-button="true" confirm-text="是"
		confirmColor="#F76D11" cancelText="否" @confirm="onConfirmShowfirm" @cancel="confirmShow = false"></up-modal>
</template>
<script setup lang="ts">
	import { ref, reactive, getCurrentInstance } from "vue";
	import { onLoad, onShow } from "@dcloudio/uni-app";
	import NavBar from "@/components/navbar.vue"
	import { roleInfoStore } from '@/stores/user'
	const { proxy } = getCurrentInstance()
	const contentHeight = ref('100vh')
	const statusBarHeight = ref(88)
	const row1ActiveBg = ref(proxy.$config.baseUrl + '/cz_row1_active.png')
	const sId = ref(0)
	const curTime = ref()
	const roleInfo = roleInfoStore()
	const role = ref()
	onLoad((e) => {
		uni.getSystemInfo({
			success: function (info) {
				statusBarHeight.value = (info.statusBarHeight + 44) * 2
				contentHeight.value = `calc(100vh - ${statusBarHeight.value + 68}rpx)`
			}
		});
		if (e.shopid) {
			sId.value = e.shopid
		}
		curTime.value = proxy.$gloab.formatDateY_M_D_H_M_S(new Date(), '-')
		getUserInfo()
		role.value = roleInfo.role

	})
	// 个人信息
	const userInfo = ref({
		avatar: ''
	})
	const getUserInfo = async () => {
		let res = await proxy.$http('my.getUserInfo')
		let data = res.data
		userInfo.value = data
		roleInfo.is_normal_user = data.is_normal_user
		roleInfo.is_jituan_user = data.is_jituan_user
		getShopDetail()
		// roleInfo.car_normal_type_list = data.car_normal_type_list
		// roleInfo.car_jituan_type_list = data.car_jituan_type_list
		// if (roleInfo.role == 1) {
		// 	row2List.value = roleInfo.car_jituan_type_list
		// } else {
		// 	row2List.value = roleInfo.car_normal_type_list
		// }
	}
	// 店铺详情
	const storeDetail = ref({})
	const getShopDetail = async () => {
		let res = await proxy.$http('index.getShopDetail', { shop_id: sId.value })
		let data = res.data

		// navTitle.value = data.shop_name
		storeDetail.value = data
		let dArr = data.city.split('/')
		positionInfo.value.province_name = dArr[0]
		positionInfo.value.city_name = dArr[1]
		positionInfo.value.area_name = dArr[2]
		getWashNum()

		// if (data.shop_images) {
		// 	imgList.value = data.shop_images.split(',')
		// }
		// isShowPage.value = true
	}
	// 
	const positionInfo = ref({
		province_name: '',
		city_name: '',
		area_name: ''

	})
	const washInfo = ref({
		car_jituan_num: 0,
		car_jituan_type_list: [],
		car_normal_num: 0,
		car_normal_type_list: []
	})
	const getWashNum = async () => {
		let res = await proxy.$http('my.getWashNum', { user_id: userInfo.value.id, ...positionInfo.value })
		if (res.code == 1) {
			washInfo.value = res.data
			initRow2List()
		}
	}

	const initRow2List = () => {
		if (roleInfo.role == 1) {
			row2List.value = washInfo.value.car_jituan_type_list
		} else {
			row2List.value = washInfo.value.car_normal_type_list
		}
	}
	const row2List = ref([])
	const row2ActiveIdx = ref(0)
	const onClickRow2Item = (e) => {
		row2ActiveIdx.value = e
	}
	const showConfirm = () => {
		if (row2List.value.length == 0) {
			uni.$u.toast('没有当前类型次数')
			return
		}
		confirmShow.value = true
	}
	const confirmShow = ref(false)
	const onConfirmShowfirm = () => {
		confirmShow.value = false
		washDone()
	}
	const washDone = async () => {
		let res = await proxy.$http('index.washDone', { shop_id: sId.value, car_type: row2List.value[row2ActiveIdx.value].car_type })
		if (res.code == 1) {
			isShowState.value = true
			uni.$u.toast('核销成功')
			setTimeout(() => {
				uni.reLaunch({
					url: "/pages/order/index"
				})
			}, 1000)
		}
	}
	const isShowState = ref(false)
	const switchRole = () => {
		if (role.value == 1) {
			role.value = 0
		} else {
			role.value = 1
		}
		initRow2List()
	}
	const leftClick = () => {
		uni.reLaunch({
			url: "/pages/index/index"
		})
	}
</script>
<style lang="scss" scoped>
	.state_box {
		width: 750rpx;
		padding: 20rpx 0;
		background: #ffffff;
		position: fixed;
		top: 0;
		left: 0;
	}

	.content {
		background: #F7F8FC;
		padding: 10rpx 18rpx;
		padding-bottom: 64rpx;

		.goods_box {
			padding: 20rpx;
			background: #FFFFFF;
			box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
			border-radius: 10rpx;
		}

		.row2 {
			display: flex;
			flex-direction: column;
			align-items: center;

			.row2_list {
				flex-wrap: wrap;
				padding: 0 16rpx;

				.row1_item {
					width: 218rpx;
					height: 173rpx;
					box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
					border-radius: 12rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					background-size: 105.5% 109%;
					background-position: -6rpx -6rpx;
					background-repeat: no-repeat;
					border: 2rpx solid #ffffff;
				}

				.row1_item_active {
					border: 2rpx solid #FB845F;
				}

			}

		}

		.row3 {
			.row3_item {
				padding: 28rpx;
				padding-top: 24rpx;
				background: #FFFFFF;
				box-shadow: 2rpx 7rpx 5rpx 0rpx rgba(197, 197, 197, 0.29);
				border-radius: 10rpx;
			}
		}

		.submit_btn {
			width: 684rpx;
			height: 96rpx;
			margin: 0 auto;
			background: #FD6C25;
			border-radius: 48rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

	}

	::v-deep.u-image {
		display: flex;
		align-items: center;
	}
</style>